package com.chixing.day15_map;

import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;


public class OutputStreamDemo {
    public static void main(String[] args) {
        //写数据到d://test1//hello

        //1.创建字节写入流
        OutputStream os = null;
        try {
             os = new FileOutputStream("d://test1/hello.txt");
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
        //2.写数据
        String content = "Creates a file output stream to write to the file with the specified name. " +
                "If the second argument is true, then bytes will be written to the end of the file rather than the beginning. " +
                "A new FileDescriptor object is " +
                "created to represent this file connection.";
        try {
            os.write(content.getBytes());
        } catch (IOException e) {
            e.printStackTrace();
        }finally { //3.关闭流 释放内存，节约资源
            if (os != null){
                try {
                    os.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }

}
